package com.jlc.connPage;

import java.sql.*;







public abstract class JDBCUtil {
	static Connection con = null;
	static {
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

	public static Connection getMysqlConnection() throws SQLException {
		con = DriverManager.getConnection("jdbc:mysql://localhost:3306/MVC",
				"root", "root");
		return con;
	}

	public static void cleanup(Connection con) throws SQLException {
		if (con != null) {
			con.close();
		}

	}

	public static void cleanup(Connection con, Statement st) {
		try {
			if (con != null) {
				con.close();
			}
			if (st != null) {
				st.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public static void cleanup(Connection con, Statement st, ResultSet rs) {
		try {
			if (con != null) {
				con.close();
			}
			if (st != null) {
				st.close();
			}
			if (rs != null) {
				rs.close();
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public static void cleanup(Connection con, PreparedStatement ps) {
		try {
			if (con != null) {
				con.close();
			}
			if (ps != null) {
				ps.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public static void cleanup(Connection con, PreparedStatement ps,
			ResultSet rs) {
		try {
			if (con != null) {
				con.close();
			}
			if (ps != null) {
				ps.close();
			}
			if (rs != null) {
				rs.close();
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
